package com.example.crud.rest;

import com.example.crud.domain.SUser;
import com.example.crud.service.SUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * SUser模块接口
 *
 * @author Roger
 * @since 2021/6/16
 */
@RestController
@RequestMapping("/suser")
public class SUserController {
    @Autowired
    SUserService sUserService;

    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public SUser getSUser(@PathVariable("id") int id) {
        SUser sUser = sUserService.getSUser(id);
        return sUser;
    }

    @RequestMapping(method = RequestMethod.POST)
    public int createSUser(@RequestBody SUser sUser) {
        int id = sUserService.addSUser(sUser);
        return id;
    }

    @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
    public int updateSUser(@PathVariable("id") int id,
                      @RequestBody SUser sUser) {
        if(sUser!= null){
            sUser.setId(id);
        }
        int num = sUserService.updateSUser(sUser);
        return num;
    }
    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    public int deleteSUser(@PathVariable("id") int id){
        int num = sUserService.deleteSUser(id);
        return num;
    }

}
